# -  *  - coding:utf-8  -  *  -
from selenium.webdriver.common.by import By

from public.common.basepage import Page, elementsInfo, loginData


class LoginPage(Page):
    username = (elementsInfo.readExcel(1, 2), elementsInfo.readExcel(1, 3))
    password = (elementsInfo.readExcel(2, 2), elementsInfo.readExcel(2, 3))
    submit = (elementsInfo.readExcel(3, 2), elementsInfo.readExcel(3, 3))
    saveInfo = (elementsInfo.readExcel(4, 2), elementsInfo.readExcel(4, 3))
    nameErroIcon = (elementsInfo.readExcel(5, 2), elementsInfo.readExcel(5, 3))
    nameIcon = (elementsInfo.readExcel(6, 2), elementsInfo.readExcel(6, 3))
    pwdErroIcon = elementsInfo.readExcel(7, 2), elementsInfo.readExcel(7, 3)
    pwdIcon = elementsInfo.readExcel(8, 2), elementsInfo.readExcel(8, 3),
    nameErro = elementsInfo.readExcel(9, 2), elementsInfo.readExcel(9, 3)

    loginList = [
        [loginData.readExcel(1, 0), loginData(1, 1)],  # 用户名及密码均为空
        [loginData.readExcel(2, 0), loginData(2, 1)],  # 用户名为空
        [loginData.readExcel(3, 0), loginData(3, 1)],  # 密码为空
        [loginData.readExcel(4, 0), loginData(4, 1)],  # 用户名错误
        [loginData.readExcel(5, 0), loginData(5, 1)],  # 密码错误
        [loginData.readExcel(6, 0), loginData.readExcel(6, 1)]  # 用户名及密码均错误
    ]

    def login(self, username=None, password=None):
        # 登录的统一函数
        self.sendKeys(self.username, username)
        self.sendKeys(self.password, password)
        self.is_click(*self.submit)

    def is_icon(self, loc, name):
        attr = self.getAttribute(loc, name)
        return attr

    def erro_info(self, loc):
        # 获取错误提示信息
        el = self.get_text(*loc)